package modle

import (
	"net/http"
	"pd/utils"

	"github.com/gin-gonic/gin"
)

func (d *deviceInfos) updateRecentUseTime(c *gin.Context) {
	request := &utils.UpdateRecentUseTimeRequest{}
	err := c.ShouldBindJSON(request)
	if err != nil {
		utils.RequestParamsErr.Msg = err.Error()
		c.JSON(http.StatusOK, utils.RequestParamsErr)
		return
	}

	deviceInfo := NewDeviceInfos()
	err = request.ParamsVerify()
	if err != nil {
		utils.RequestParamsErr.Msg = err.Error()
		c.JSON(http.StatusOK, utils.RequestParamsErr)
		return
	}
	err = deviceInfo.GetDeviceInfo(request.User, request.DeviceName)
	if err != nil {
		utils.InnerParamsErr.Msg = err.Error()
		c.JSON(http.StatusOK, utils.InnerParamsErr)
		return
	}

	err = deviceInfo.UpdateRecentUseTime()
	if err != nil {
		utils.InnerParamsErr.Msg = err.Error()
		c.JSON(http.StatusOK, utils.InnerParamsErr)
		return
	}

	utils.RequestSuccess.Msg = "update success"
	c.JSON(http.StatusOK, utils.RequestSuccess)
}
